<template>
  <van-nav-bar
      title="订单详情"
      left-text="返回"
      left-arrow
      @click-left="onClickLeft"
  />
  <van-card
      num="1"
      :price="order.price"
      :title="goods.name"
      thumb="https://img.yzcdn.cn/vant/ipad.jpeg"
  >
    <template #tags>

    </template>
  </van-card>
  <div v-if="order.status==1">
    <van-submit-bar :loading="loading" :price="order.price*100" button-text="付款" @submit="onSubmit" />
  </div>
</template>

<script>
import {getOrder} from "@/api/order";
import {getGoodsDetail} from "@/api/goods";
import {Toast} from "vant";

export default {
  name: "Order",
  created() {
    let id = this.$route.query.id;
    getOrder(id).then((res) => {
      this.order = res.data
      if(res.code==200){
        getGoodsDetail(res.data.goods_id).then((goods)=>{
          this.goods = goods.data
        })
      }
    })
  },
  data(){
    return {
      order:{},
      goods:{},
      loading:false
    }
  },
  methods: {
    onClickLeft() {
      history.back()
    },
    onSubmit() {
      let that=this
      this.loading = true;
      this.sleep(1000).then(()=>{
        Toast.fail("您没有配置支付appid")
        that.loading = false
      })

    },
    sleep(time){
      return new Promise(function(resolve){
        setTimeout(resolve, time);
      });
    }
  }
}
</script>

<style scoped>

</style>
